package 数组完成房屋租赁系统;

import java.util.ArrayList;

//对房屋信息进行crud的操作工具类
public class HouseService {
    ArrayList<House> houses=new ArrayList<>();
    House house;
    public void addDefault(){
        House house1=new House("小杨","1509107888","宝鸡市",500,"未出租");
        House house2=new House("小宋","1777107888","宝鸡市",800,"未出租");
        House house3=new House("小杜","1888888888","安康市",1000,"未出租");
        houses.add(house1);
        houses.add(house2);
        houses.add(house3);
    }
    /**
        返回所有房屋信息
     */
    public ArrayList<House> gteHouse(){
        return houses;
    }

    /**
        添加一个新的房屋对象
        若返回true就是添加成功//返回false 就是添加失败
     */
    public boolean add(House house){
        return houses.add(house);
    }

    /**
     * @param delId  删除指定id对象的房屋对象
     * @return   返回值是true，删除成功，返回值是false 删除失败
     */
    public boolean delete(int delId){
        house=houses.get(delId);
        return houses.remove(house);
    }
    public void set(int setId,House house){
        houses.set(setId,house);
    }
    public House findById(int findId){
        house=houses.get(findId);
        return house;
    }
}
